<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	            <td style="width:100%;">
	            	<sec:authorize url='/logistics_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
	                </sec:authorize>
	                <sec:authorize url='/logistics_edit.do'>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
	                </sec:authorize>
	                <sec:authorize url='/logistics_del.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>  
	                </sec:authorize>
	            </td>
	                <td style="white-space:nowrap;">
	            	<span>公司名称</span>
	                <input id="name" class="mini-textbox" emptyText="请输入公司名称" style="width:150px;" onenter="onKeyEnter"/>   
	                <span>联系人</span>
	                <input id="conPeo" class="mini-textbox" emptyText="请输入联系人" style="width:150px;" onenter="onKeyEnter"/>   
	                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
	            </td>
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid" idField="id" pageSize="20" url="logistic_view.do" style="width:100%;height:100%;" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn"></div>
			<div name="action" width="10%" headerAlign="center" align="center" renderer="onActionRenderer">相关操作</div>
			<div field="name" width="25%" headerAlign="center" align="center">公司名称</div>
			<div field="serialNum" width="15%" headerAlign="center" align="center">编号</div>
			<div field="conPeo" width="10%" headerAlign="center" align="center">联系人</div>
			<div field="phone" width="20%" headerAlign="center" align="center">联系电话</div>
			<div field="remark" width="20%" headerAlign="center" align="center">备注</div>
		</div>
	</div>
	</div>

<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.load();
	
	 function search() {
		 	var name = mini.get("name").getValue();
		    var conPeo = mini.get("conPeo").getValue();
		    grid.load({
		    	name: name,
		    	conPeo: conPeo,
		    });
		}
	 
	//相关操作
	function onActionRenderer(e) {
		return '<a style="width:150px;" href="javascript:viewDetail()">查看详细</a>';
	}
	
	function viewDetail(){
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "logistics_view.do",
                title: "物流公司明细", width: 630, height: 550,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { row: row };
                    iframe.contentWindow.SetData(data);
                }
            });
        } else {
            alert("请选中一条记录");
        }
	}

	function add() {
	    mini.open({
	        url: "logistics_add.do",
	        title: "新增物流", width: 680, height: 590,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action: "new"};
	            iframe.contentWindow.SetData(data);
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
	        }
	    });
	}
	
	function edit() {
        var row = grid.getSelecteds();
        if (row.length == 1) {
            mini.open({
                url: "logistics_edit.do",
                title: "编辑物流信息", width: 680, height: 580,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", row: row[0] };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                	if(action == 'succ'){
    	        		mini.showMessageBox({
    	                    title: "提示",
    	                    showModal:false,
    	                    iconCls: "mini-messagebox-info",
    	                    message: "修改成功！",
    	                    timeout: 3000,
    	                    x: 'right',
    	                    y: 'bottom'
    	                });
    		            grid.reload();
    	        	}
                }
            });
        } else {
            mini.alert("请选中一条记录");
        }
    }
	
	function remove() {
		var rows = grid.getSelecteds();
		if (rows.length > 0) {
	    	mini.confirm("确定删除选中记录？", "删除",
            	function (action) {
                   if (action == "ok") {
                	   var arr = new Array();
	               		$.each(rows,function(i,v){
	               			arr.push(v.id);
	               		});
	               		var rids = arr.join("-");
	                   $.post("logistics_del.do",{id:rids},function(data){
	                		mini.showMessageBox({
	                            title: "提示",
	                            showModal:false,
	                            iconCls: "mini-messagebox-info",
	                            message: "已删除！",
	                            timeout: 3000,
	                            x: 'right',
	                            y: 'bottom'
	                        });
	                   		grid.reload();
	                   	},"json");
                   }
           });
	    } else {
	        alert("请选中一条记录");
	    }
	}
	
</script>
</body>
</html>